<?php


namespace App\Http\Controllers\Api;


use App\Helpers\Api\ApiResponse;
use App\Helpers\Api\MiniProgramTrait;
use App\Helpers\Api\UnionPayTrait;
use App\Http\Controllers\Controller;
use App\Models\User;
use Dingo\Api\Routing\Helpers;

class BaseController extends Controller
{

    use Helpers, ApiResponse, MiniProgramTrait, UnionPayTrait;

    /**
     * Get the token array structure.
     * @param $token
     * @return mixed
     */
    protected function respondWithToken($token)
    {
        return $this->success([
            'info' => $this->getUser(),
            'access_token' => $token,
            'token_type' => 'Bearer',
            'expires_in' => auth()->factory()->getTTL() * 60
        ]);
    }

    /**
     * @return User
     */
    protected function getUser()
    {
//        return User::find(1);
        return auth('api')->user();
    }

    function paginate($pagination) {
        $arr = [
            'list' => $pagination->items(),
            'total' => $pagination->total(),
            'has_more_page' => $pagination->hasMorePages()
        ];
        return $this->success($arr);
    }

    protected function cache($input, $tags, $func) {
        ksort($input);
        $cache_key = substr(md5(http_build_query($input)), 8, -8);
        return \Cache::tags($tags)->rememberForever($cache_key, $func);
    }

}

